package com.mtk.launcher.activity;

import android.content.Intent;
import android.os.Bundle;
import android.provider.Settings;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.cdl.library.view.MyToastView;
import com.cdl.library.view.WaitDialogUtil;
import com.mtk.launcher.BuildConfig;
import com.mtk.launcher.service.MyService;

public class BaseActivity extends AppCompatActivity {

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        supportRequestWindowFeature(Window.FEATURE_NO_TITLE);//取消标题栏
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        initScreenFit();
        startService(new Intent(BaseActivity.this, MyService.class));
    }

    //关闭屏幕自动旋转
    private void initScreenFit() {
        if (BuildConfig.DEBUG) {
            return;
        }
        Settings.System.putInt(
                getContentResolver(),
                Settings.System.ACCELEROMETER_ROTATION,
                0
        );
    }

    public void showToastView(String desc) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                MyToastView.getInstance().Toast(BaseActivity.this, desc);
            }
        });
    }

    private WaitDialogUtil waitDialogUtil;

    public void showWaitDialogUtil(boolean isShow) {
        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (waitDialogUtil == null) {
                    waitDialogUtil = new WaitDialogUtil(BaseActivity.this);
                }
                if (isShow) {
                    waitDialogUtil.showDialog();
                } else {
                    waitDialogUtil.cancelDialog();
                }
            }
        });
    }

}
